<template>
	<div class="layout-pd">
		<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
			<el-table-column prop="hid" label="id" width="300" />
			<el-table-column prop="name" label="作业名称"  width="300"></el-table-column>
			<!-- <el-table-column prop="roleSign" label="角色标识" show-overflow-tooltip></el-table-column>
				<el-table-column prop="sort" label="排序" show-overflow-tooltip></el-table-column> -->

			<!-- <el-table-column prop="describe" label="角色描述" show-overflow-tooltip></el-table-column> -->
			<el-table-column prop="endtime" :formatter="getLocalTime" label="截止时间"  width="400"></el-table-column>
		
			<el-table-column label="操作"  width="300">
				<template #default="scope">
					<el-button size="small" text type="primary" @click="Jump(scope)">查看</el-button>
					<!-- <el-button :disabled="scope.row.roleName === '超级管理员'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>  -->
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup lang="ts" name="funWangEditor">
import { storeToRefs } from 'pinia';
import { useUserInfo } from '/@/stores/userInfo';
import { onMounted, reactive, ref } from 'vue';
import { map } from '/@/api/mapfiles/index';
import router from '/@/router';
import { Session } from '/@/utils/storage';
import { NextLoading } from '/@/utils/loading';



// 定义变量内容
const storesUserInfo = useUserInfo();
const { userInfos } = storeToRefs(storesUserInfo);
const userAuth = ref('');

// 定义变量内容
const state = reactive<SysRoleState>({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			hids: [],
			search: '',
			pageNum: 1,
			pageSize: 10,
			states: [],
			getatates:[],
		},
	},
});

// 初始化用户权限
const initUserAuth = () => {
	userAuth.value = userInfos.value.roles[0];
};


// 获取发布的作业
const onRadio = async () => {
	map().getHomeWork().then(res => {
		state.tableData.data = res.data;
		for (let i = 0; i < state.tableData.data.length; i++) {
			state.tableData.param.states.push(res.data[i].hid)
			Session.set(res.data[i].hid, JSON.stringify(res.data[i].content))
		}
		//获取作业状态
		map().getState(state.tableData.param.states).then(res => {
			 localStorage.setItem('states', JSON.stringify(res.data))
		})
		state.tableData.param.getatates=JSON.parse(localStorage.getItem("states") || '{}')
	})


};


//格式化后端返回来的时间
function getLocalTime(value: any) {
	let time = value.endtime[0] + '-' + value.endtime[1] + '-' + value.endtime[2] + ' ' + value.endtime[3] + ':' + value.endtime[4] + ':' + value.endtime[5]
	return time
}



//跳转到具体页面
const Jump = (scope: any) => {
	localStorage.setItem('hid', JSON.stringify(scope.row.hid))
	router.push("/fun/clipboard")
}


// 页面加载时
onMounted(() => {
	initUserAuth()
	onRadio()
});


</script>



<!-- <template>
	<div class="editor-container layout-pd">
		<el-card shadow="hover" header="wangeditor富文本编辑器">
			<el-alert
				title="感谢优秀的 `wangeditor`，项目地址：https://github.com/wangeditor-team/wangEditor"
				type="success"
				:closable="false"
				class="mb15"
			></el-alert>
			<Editor v-model:get-html="state.editor.htmlVal" v-model:get-text="state.editor.textVal" :disable="state.editor.disable" />
		</el-card>
	</div>
</template>

<script setup lang="ts" name="funWangEditor">
import { defineAsyncComponent, reactive } from 'vue';

// 引入组件
const Editor = defineAsyncComponent(() => import('/@/components/editor/index.vue'));

// 定义变量内容
const state = reactive({
	editor: {
		htmlVal:
			'<p><span style="color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); font-size: 14px;">胡歌，1982年9月20日出生于上海市徐汇区，中国内地影视男演员、流行乐歌手，</span><a href="https://baike.baidu.com/item/%E6%B0%91%E7%9B%9F/1971441?fromModule=lemma_inlink" target="_blank" style="text-indent: 28px; text-align: start;">民盟</a><span style="color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); font-size: 14px;">盟员</span><span style="color: rgb(51, 102, 204); background-color: rgb(255, 255, 255); font-size: 12px;"><sup> [1]</sup></span><a href="" target="" style="text-indent: 28px; text-align: start;"> </a><span style="color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); font-size: 14px;"> ，毕业于</span><a href="https://baike.baidu.com/item/%E4%B8%8A%E6%B5%B7%E6%88%8F%E5%89%A7%E5%AD%A6%E9%99%A2/1736818?fromModule=lemma_inlink" target="_blank" style="text-indent: 28px; text-align: start;">上海戏剧学院</a><span style="color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); font-size: 14px;">表演系。</span></p>',
		textVal: '胡歌，1982年9月20日出生于上海市徐汇区，中国内地影视男演员、流行乐歌手，民盟盟员 [1]  ，毕业于上海戏剧学院表演系。',
		disable: false,
	},
});
</script> -->
